package com.ahzx.banner.controller;

import com.ahzx.banner.domain.Banner;
import com.ahzx.banner.service.BannerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * banner管理控制层
 * @Author syg
 * @Date 2021/4/27 15:14
 * @Desc To be or not to be,that is a question.
 */
@RestController
@RequestMapping("/banner")
public class BannerController extends BaseController {

    @Autowired
    private BannerService bannerService;


    /**
     * 查询banner列表
     * @return
     */
    @GetMapping
    public TableDataInfo list() {
        startPage();
        List<Banner> banners = bannerService.selectBannerList();
        return getDataTable(banners);
    }

    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable Integer id) {
        return AjaxResult.success();
    }

    /**
     * 插入banner信息
     * @param banner
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Banner banner) {
        bannerService.insertBanner(banner);
        return AjaxResult.success();
    }

    /**
     * 删除banner信息
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        bannerService.deleteBannerById(id);
        return AjaxResult.success();
    }

    /**
     * 更新banner信息
     * @param banner
     * @return
     */
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Banner banner) {
        bannerService.updateBannerById(banner);
        return AjaxResult.success();
    }
}
